load("//bazel:mongo_src_rules.bzl", "mongo_cc_binary", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "stitch_support",
    srcs = [
        "stitch_support.cpp",
    ],
    hdrs = [
        "stitch_support.h",
        "//src/mongo/embedded:api_common.h",
    ],
    additional_linker_inputs = select({
        "@platforms//os:linux": [
            ":libstitch_support.version_script.lds",
        ],
        "@platforms//os:macos": [
            ":libstitch_support.exported_symbols_list.lds",
        ],
        "@platforms//os:windows": [
            ":stitch_support.def",
        ],
        "//conditions:default": [],
    }),
    copts = [
        "-Isrc/mongo/embedded",
    ],
    local_defines = [
        "STITCH_SUPPORT_COMPILING",
    ] + select({
        "//bazel/config:linkstatic_enabled": [
            "STITCH_SUPPORT_STATIC",
        ],
        "//conditions:default": [],
    }),
    non_transitive_dyn_linkopts = select({
        "@platforms//os:linux": [
            "-Wl,--version-script=$(location :libstitch_support.version_script.lds)",
        ],
        "@platforms//os:macos": [
            "-Wl,-exported_symbols_list,$(location :libstitch_support.exported_symbols_list.lds)",
        ],
        "@platforms//os:windows": [
            "/DEF:$(location :stitch_support.def)",
        ],
        "//conditions:default": [],
    }),
    tags = ["stitch_support"],
    deps = [
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:vector_clock_trivial",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/query/collation:collator_factory_icu",
        "//src/mongo/db/query/collation:collator_factory_interface",
        "//src/mongo/db/query/write_ops:parsed_update",
    ],
)

mongo_cc_unit_test(
    name = "stitch_support_test",
    srcs = [
        "stitch_support_test.cpp",
    ],
    copts = [
        "-Isrc/mongo/embedded",
    ],
    has_custom_mainline = True,
    tags = [
        "mongo_unittest_second_group",
        "stitch_support_test",
    ],
    target_compatible_with = select({
        "//bazel/config:shared_archive_enabled": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [
        "stitch_support",
        "//src/mongo/db:service_context_non_d",
        "//src/mongo/unittest",
    ],
)
